# -*- coding: utf-8 -*-
# Sacado del 4.19 del python cookbook
 ###############################################
 ##                                             ##
 ##   Setup                                      ##
 ##                                              ##
 ##   Empresa Básica                             ##
 ##                                              ##
 ##   por Críptidos Digitales                    ##
 ##   GPL (c)2008                                ##
  ##                                             ##
    ###############################################

import os, fnmatch
from distutils.core import setup
import py2exe

import EB

def listFiles( root, patterns='*', recurse=0, return_folders=0 ) :
    pattern_list = patterns.split( ';' )                    # Expand patterns from semicolon-separated string to list
    class Bunch :                                           # Collect input and output arguments into one bunch
        def __init__( self, **kwds ) : self.__dict__.update( kwds )
    arg = Bunch( recurse=recurse, pattern_list=pattern_list, return_folders=return_folders, results=[ ] )
    def visit( arg, dirname, files ) :
        for name in files :                                 # Append to arg.results all relevant files (and perhaps folders)
            fullname = os.path.normpath( os.path.join( dirname, name ) )
            if arg.return_folders or os.path.isfile( fullname ) :
                for pattern in arg.pattern_list :
                    if fnmatch.fnmatch( name, pattern ) :
                        arg.results.append( fullname )
                        break
        if not arg.recurse : files[ : ] = [ ]               # Block recursion if recursion was disallowed
    os.path.walk( root, visit, arg )
    return arg.results


def filterFiles( root, patterns='*', recurse=0, return_folders=0 ) :
    archivos = listFiles( root, patterns, recurse, return_folders )
    filtered = [ ]
    estosDirectoriosNo = ( 'CVS', 'DIST', 'BUILD', 'ATICO', 'RESOURCES', '.svn' )
    for archivo in archivos :
        encontrado = False
        for directorio in estosDirectoriosNo :
            if directorio in archivo.upper( ) :
                encontrado = True
        if not encontrado :
            filtered.append( archivo )
    return filtered

app = EB.MyApp([])

setup(name = "Empresa Basica",
        version = "%s" % app.info['version'],
        windows = ["EB.py",
            { "icon_resources" : [ ( 1, "imagenes/EB.ico" ) ],
              "script" : "EB.py" }
        ],
        data_files = [
            ('imagenes', filterFiles( 'imagenes', '*.png;*.jpg;*.gif;*.ico')),
            ('', ('changelog.txt', ))
        ],
        options = {
            "py2exe": { "packages": [ "encodings", "sqlalchemy" ], "includes":["sip"]
                      }
        }
    )


# uso : python setup.py py2exe

